<template>
   <div >
   <span v-show="1==2"> {{rowKeyValue}}</span>

    <div v-if="columnAttribute.component=='input'">
         <a-badge v-if="record[defaultSettings.常量.表格是否可编辑属性] && !columnAttribute['disabled']" :dot="showError">
            <a-input  :value="record[columnAttribute.field]"  style="width:100%"  @change="onchange"/>
         </a-badge>
         <span v-else>{{record[columnAttribute.field]}}</span>
    </div>
    <div v-else-if="columnAttribute.component=='select'">
        
        <a-badge v-if="record[defaultSettings.常量.表格是否可编辑属性] && !columnAttribute['disabled'] " :dot="showError" style="width:100%">
            <a-select style="width:100%" @change="onchange"  show-search :value="record[columnAttribute.field]">
                <a-select-option value="">请选择</a-select-option>
                <a-select-option v-for="(item, key) in $store.state.dict.dictInfo[columnAttribute.dictCode].dictInfo" :key="key" :value="item['itemValue']">
                    <span style="display: inline-block;width: 100%" :title="item['itemText']">
                        {{item['itemText']}}
                    </span>
                </a-select-option>
            </a-select>
        </a-badge>
        <span v-else>{{dictText($store.state.dict.dictInfo[columnAttribute.dictCode].dictInfo,record[columnAttribute.field]+"")}}</span>               
       
    </div>
   </div>
</template>

<script>
import defaultSettings from '@/config/defaultSettings'
import {SysMixin} from '@/mixins/SysMixin'
export default {
    name:'LEditTableColumn',
    components: {
        
    },
    mixins:[SysMixin],
    props:{
      record:{
        type:Object,
        default:()=>{}
      },
      index:Number,
      value:String,
      columnAttribute:{
        type:Object,
        default:()=>{}
      },
      table:Object,
      rowKey:String,
      rowKeyValue:String,
    },
    mixins:[],
    computed:{
       
    },
    watch:{
       
    },
    data () {
        return {
            defaultSettings,
            showError:false 
        }
    },
    methods:{
       
        onchange(e){
            let value
            if(e.target && e.target){
                value = e.target.value
            }else{
                value = e
            }
          
            this.record[this.columnAttribute.field] = value
            //非空验证
            if(this.columnAttribute.required && this.columnAttribute.required==true && !value){
                this.showError = true
            }else{
                this.showError = false
            }

            if(this.showError){
                return false
            }

            //正则验证
            if(this.columnAttribute.regExp){
                if(this.columnAttribute.regExp.test(value)){
                    this.showError = false
                }else{
                    this.showError = true
                }
            }
            
            // this.table.refreshData()
        }
       
    },
    mounted(){
        console.log(this.$store.state.dict.dictInfo)
    },
    created(){
       
    }
}
</script>
